<?php 


require "database.php";


$base=new Db;

$p=$_POST['page'];

$pid=$_POST['pid'];

$searchtext=$_POST["searchtext"];

if($pid){
    
    
    $sum=$base->doSql('select * from t_qiyeku where pid="'.$pid.'" and status=1');
    
    if($p){
        
        $page=($p-1)*10;
        $r=$base->doSql('select * from t_qiyeku where pid="'.$pid.'" and status=1 limit '.$page.',10');
    }else{
        $r=$base->doSql('select * from t_qiyeku where pid="'.$pid.'" and status=1 limit 0,10');
    }
    
    $cout=count($sum);

}elseif($searchtext){
     
    
    
    $sum=$base->doSql('select * from t_qiyeku where qy_name like "%'.$searchtext.'%" or qy_adds like "%'.$searchtext.'%" or qy_desc like "%'.$searchtext.'%" or qy_mobile like "%'.$searchtext.'%" and status=1');
    
    if($p){
        
        $page=($p-1)*10;
        $r=$base->doSql('select * from t_qiyeku where qy_name like "%'.$searchtext.'%" or qy_adds like "%'.$searchtext.'%" or qy_desc like "%'.$searchtext.'%" or qy_mobile like "%'.$searchtext.'%" and status=1 limit '.$page.',10');
    }else{
        $r=$base->doSql('select * from t_qiyeku where qy_name like "%'.$searchtext.'%" or qy_adds like "%'.$searchtext.'%" or qy_desc like "%'.$searchtext.'%" or qy_mobile like "%'.$searchtext.'%" and status=1 limit 0,10');
    }
    
    $cout=count($sum);
    
}else{
    
    
    $sum=$base->doSql('select * from t_qiyeku where pid=1 and status=1');
    
    if($p){
        
        $page=($p-1)*10;
        $r=$base->doSql('select * from t_qiyeku where pid=1 and status=1 limit '.$page.',10');
    }else{
        $r=$base->doSql('select * from t_qiyeku where pid=1 and status=1 limit 0,10');
    }
    
    $cout=count($sum);
   
}

return json([
    "count" =>$cout,
    "data"  =>$r
]);